// Uppercase the first letter of each word found after a space.
// By Ben 04/10/2018

#include <iostream>
using namespace std;

string ProperCase(string source){
	int i = 0;
	int idx = 0;
	string s0 = source;
	if (source.length() == 0){
		return "";
	}
	//Uppercase first letter.
	s0[0] = toupper(s0[0]);

	//Look for chars that come after a space
	while (i < s0.length()){
		//Find a space
		if (s0[i] == ' '){
			//Index to next address
			idx = (i + 1);
			//Check index if not out of range
			if (i < s0.length()){
				//Check that the next char after the save is not a space
				if (s0[i + 1] != ' '){
					//Uppercase the char
					s0[i + 1] = toupper(s0[i + 1]);
				}
			}
		}
		//INC counter
		i++;
	}
	//Return
	return s0;
}

int main(){
	//A string to fix
	string s0 = "c++ programming is a lot of fun.";
	//Output
	std::cout << ProperCase(s0).c_str() << endl;

	system("pause");
	return 0;
}